import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    graphData: {
      nodes: [],
      edges: []
    }
  },
  mutations: {
    SET_GRAPH_DATA(state, data) {
      state.graphData = data
    },
    ADD_NODE(state, node) {
      state.graphData.nodes.push(node)
    },
    ADD_EDGE(state, edge) {
      state.graphData.edges.push(edge)
    }
  },
  actions: {
    updateGraphData({ commit }, data) {
      commit('SET_GRAPH_DATA', data)
    },
    addNode({ commit }, node) {
      commit('ADD_NODE', node)
    },
    addEdge({ commit }, edge) {
      commit('ADD_EDGE', edge)
    }
  },
  getters: {
    getGraphData: state => state.graphData
  }
}) 